package com.ysj.demo.accompanynetwork.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ysj.demo.accompanynetwork.R;
import com.ysj.demo.accompanynetwork.bean.ConsumeIntegralBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 80530 on 2018/8/8.
 */

public class HomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<ConsumeIntegralBean> mList;
    private LayoutInflater mLayoutInflater;

    public HomeAdapter(Context context, List<ConsumeIntegralBean> list) {
        this.mContext = context;
        this.mList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void clearList() {
        if (null != mList) {
            mList.clear();
            notifyDataSetChanged();
        }
    }

    public void addList(List<ConsumeIntegralBean> otherList) {
        if (null == mList) {
            mList = new ArrayList<>();
        }
        mList.addAll(otherList);
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mLayoutInflater.inflate(R.layout.item_one_person_layout, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            MyHolder holder1 = (MyHolder) holder;
            ConsumeIntegralBean item = mList.get(position);
//            switch (item.getType()) {
//                case 1:
//                    holder1.typeTv.setText("付费刷新");
//                    // holder.iconTv.setTextColor(mContext.getResources().getColor(R.color.green));
//                    holder1.iconTv.setSelected(false);
//                    holder1.iconTv.setText("-" + item.getCoin());
//                    break;
//                default:
//                    holder1.typeTv.setText("充值");
//                    holder1.iconTv.setSelected(true);
//                    holder1.iconTv.setText("+" + item.getCoin());
//                    break;
//            }
//            holder1.dateTv.setText(item.getDate());
//            holder1.remarkTv.setText(item.getRemarks());
        }

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    //定义内部类继承ViewHolder
    class MyHolder extends RecyclerView.ViewHolder {
        private TextView typeTv, iconTv, dateTv, remarkTv;

        public MyHolder(View view) {
            super(view);
            typeTv = view.findViewById(R.id.type_tv);
            iconTv = view.findViewById(R.id.icon_tv);
            dateTv = view.findViewById(R.id.date_tv);
            remarkTv = view.findViewById(R.id.remark_tv);
        }
    }
}